package com.example.demo;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.handle.Action;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.FilterChain;

/**
 * @author airhead
 */
@Component(tag = "admin", index = 1, delivered = false)
@Slf4j
public class AuthFilter extends BaseFilter {

  @Override
  public void doFilter(Context ctx, Action action, FilterChain chain) throws Throwable {
    if (action == null) {
      log.info("do something, action is null");
      chain.doFilter(ctx);
      return;
    }

    log.info("do something, action is not null");
    chain.doFilter(ctx);
  }

  /** 判断是否为 ajax 请求 */
  boolean isAjaxRequest(Context ctx) {
    return "XMLHttpRequest".equalsIgnoreCase(ctx.header("X-Requested-With"));
  }
}
